package com.wudl.flink.stream.source

import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}

object WorkCount {

  def main(args: Array[String]): Unit = {

    // 获取flink 的上下文

    val env = StreamExecutionEnvironment.getExecutionEnvironment
    // 接收socket 的流
    val strStream:DataStream[String] = env.socketTextStream("10.204.125.240",8888)
    // flatMap 和 Map 需要引用的隐式转换
    import org.apache.flink.api.scala._
    val dataStream:DataStream[(String,Int)] = strStream.flatMap(_.split(" ")).filter(_.nonEmpty).map((_,1)).keyBy(0).sum(1)
    dataStream.print().setParallelism(1)
    env.execute()




  }
}
